package com.edu.exam.entity.quality.monitoring;

import com.edu.exam.enums.quality.monitoring.ViolationSeverity;
import com.edu.exam.enums.quality.monitoring.ViolationStatus;
import com.edu.exam.enums.quality.monitoring.FollowUpStatus;
import com.edu.exam.enums.quality.monitoring.UrgencyLevel;
import com.edu.exam.enums.quality.monitoring.ConfidentialityLevel;
import com.edu.exam.enums.quality.monitoring.PatrolApprovalStatus;
import com.edu.exam.enums.quality.monitoring.ViolationUrgencyLevel;
import com.edu.exam.enums.quality.monitoring.ViolationConfidentialityLevel;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 违规记录实体类
 *
 * 负责管理巡考过程中发现的违规违纪情况
 * 根据E-05-巡考管理模块设计实现
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
public class ViolationRecord {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "record_id", nullable = false)
    private Long recordId;

    @Column(name = "task_id", nullable = false)
    private Long taskId;

    @Column(name = "violation_type", nullable = false, length = 100)
    private String violationType;

    @Column(name = "violation_description", nullable = false, columnDefinition = "TEXT")
    private String violationDescription;

    @Column(name = "student_info", length = 500)
    private String studentInfo; // 涉及学生信息（脱敏）

    @Column(name = "evidence_urls", columnDefinition = "TEXT")
    private String evidenceUrls; // 证据照片URL列表（JSON格式）

    @Enumerated(EnumType.STRING)
    @Column(name = "severity", nullable = false, length = 20)
    private ViolationSeverity severity = ViolationSeverity.MINOR;

    @Column(name = "violation_time", nullable = false)
    private LocalDateTime violationTime;

    @Column(name = "reporter", nullable = false, length = 100)
    private String reporter;

    @Column(name = "handler", length = 100)
    private String handler;

    @Column(name = "handling_result", columnDefinition = "TEXT")
    private String handlingResult;

    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 20)
    private ViolationStatus status = ViolationStatus.REPORTED;

    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    @Column(name = "location_description", length = 500)
    private String locationDescription; // 违规发生位置

    @Column(name = "witnesses", columnDefinition = "TEXT")
    private String witnesses; // 目击者信息

    @Column(name = "immediate_action", columnDefinition = "TEXT")
    private String immediateAction; // 立即采取的措施

    @Column(name = "evidence_collected", columnDefinition = "TEXT")
    private String evidenceCollected; // 收集的证据

    @Column(name = "student_statement", columnDefinition = "TEXT")
    private String studentStatement; // 学生陈述

    @Column(name = "teacher_statement", columnDefinition = "TEXT")
    private String teacherStatement; // 教师陈述

    @Column(name = "impact_assessment", columnDefinition = "TEXT")
    private String impactAssessment; // 影响评估

    @Column(name = "preventive_measures", columnDefinition = "TEXT")
    private String preventiveMeasures; // 预防措施

    @Column(name = "follow_up_required", length = 20)
    @Enumerated(EnumType.STRING)
    private FollowUpStatus followUpRequired = FollowUpStatus.NONE;

    @Column(name = "follow_up_deadline")
    private LocalDateTime followUpDeadline; // 后续处理截止时间

    @Column(name = "follow_up_notes", columnDefinition = "TEXT")
    private String followUpNotes; // 后续处理备注

    @Column(name = "department_notified")
    private Boolean departmentNotified = false; // 是否通知相关部门

    @Column(name = "parent_notified")
    private Boolean parentNotified = false; // 是否通知家长

    @Column(name = "notification_details", columnDefinition = "TEXT")
    private String notificationDetails; // 通知详情

    @Column(name = "disciplinary_action", columnDefinition = "TEXT")
    private String disciplinaryAction; // 纪律处分措施

    @Column(name = "action_effective_date")
    private LocalDateTime actionEffectiveDate; // 处分生效日期

    @Column(name = "action_duration")
    private Integer actionDuration; // 处分期限（天）

    @Column(name = "appeal_deadline")
    private LocalDateTime appealDeadline; // 申诉截止时间

    @Column(name = "appeal_submitted")
    private Boolean appealSubmitted = false; // 是否提交申诉

    @Column(name = "appeal_details", columnDefinition = "TEXT")
    private String appealDetails; // 申诉详情

    @Column(name = "appeal_decision", columnDefinition = "TEXT")
    private String appealDecision; // 申诉决定

    @Column(name = "case_closed")
    private Boolean caseClosed = false; // 案件是否关闭

    @Column(name = "case_closure_date")
    private LocalDateTime caseClosureDate; // 案件关闭日期

    @Column(name = "case_closure_reason", columnDefinition = "TEXT")
    private String caseClosureReason; // 案件关闭原因

    @Column(name = "severity_score")
    private Integer severityScore; // 严重程度评分（1-10）

    @Column(name = "urgency_level", length = 20)
    @Enumerated(EnumType.STRING)
    private ViolationUrgencyLevel urgencyLevel = ViolationUrgencyLevel.LOW;

    @Column(name = "confidentiality_level", length = 20)
    @Enumerated(EnumType.STRING)
    private ViolationConfidentialityLevel confidentialityLevel = ViolationConfidentialityLevel.NORMAL;

    @Column(name = "external_report_required")
    private Boolean externalReportRequired = false; // 是否需要外部报告

    @Column(name = "external_report_details", columnDefinition = "TEXT")
    private String externalReportDetails; // 外部报告详情

    @Column(name = "media_attention")
    private Boolean mediaAttention = false; // 是否引起媒体关注

    @Column(name = "media_handling", columnDefinition = "TEXT")
    private String mediaHandling; // 媒体应对措施

    @Column(name = "legal_implications", columnDefinition = "TEXT")
    private String legalImplications; // 法律影响

    @Column(name = "insurance_claim", length = 200)
    private String insuranceClaim; // 保险索赔

    @Column(name = "financial_impact", columnDefinition = "TEXT")
    private String financialImpact; // 财务影响

    @Column(name = "reputation_impact", columnDefinition = "TEXT")
    private String reputationImpact; // 声誉影响

    @Column(name = "lessons_learned", columnDefinition = "TEXT")
    private String lessonsLearned; // 经验教训

    @Column(name = "policy_changes_needed", columnDefinition = "TEXT")
    private String policyChangesNeeded; // 需要的政策变更

    @Column(name = "training_recommendations", columnDefinition = "TEXT")
    private String trainingRecommendations; // 培训建议

    @Column(name = "supervisor_review", columnDefinition = "TEXT")
    private String supervisorReview; // 主管审查

    @Column(name = "reviewer_id")
    private Long reviewerId; // 审查人ID

    @Column(name = "reviewer_name", length = 100)
    private String reviewerName; // 审查人姓名

    @Column(name = "review_time")
    private LocalDateTime reviewTime; // 审查时间

    @Column(name = "approval_status", length = 20)
    @Enumerated(EnumType.STRING)
    private PatrolApprovalStatus approvalStatus = PatrolApprovalStatus.PENDING;

    @Column(name = "approved_by", length = 100)
    private String approvedBy; // 审批人

    @Column(name = "approval_time")
    private LocalDateTime approvalTime; // 审批时间

    @Column(name = "approval_comments", columnDefinition = "TEXT")
    private String approvalComments; // 审批意见

    @Column(name = "version_number")
    private Integer versionNumber = 1; // 版本号

    @Column(name = "archived")
    private Boolean archived = false; // 是否归档

    @Column(name = "archive_time")
    private LocalDateTime archiveTime; // 归档时间

    @Column(name = "archive_reason", length = 500)
    private String archiveReason; // 归档原因

    @Column(name = "tags", length = 500)
    private String tags; // 标签（逗号分隔）

    @Column(name = "metadata", columnDefinition = "TEXT")
    private String metadata; // 元数据（JSON格式）


}